package com.zegome.game.gomestory.main.scene.draw;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.zegome.facebook.IFacebookBridge;
import com.zegome.game.gomestory.main.helper.IMAction;
import com.zegome.game.gomestory.main.scene.BaseGameScreen;
import com.zegome.game.gomestory.main.scene.play.board.Board;
import com.zegome.game.main.AndroidGameController;

public class Draw3Screen extends BaseGameScreen{
	
	public Board board;
	
	public static int INDEX_MAP;
	
	public Draw3Screen(AndroidGameController controller, String name, final IFacebookBridge bridge) {
		super(controller, name,bridge);		
		setConfig(true, false, true,true);		
		initData();
	}

	public void initData(){
		
	}
	
	@Override
	public void onManagedUpdate(float pDeltaTime) {
		// TODO Auto-generated method stub
		update(pDeltaTime);
		super.onManagedUpdate(pDeltaTime);
	}
	
	public void show() {
		ctr.a.soundOnOff();
		ctr.a.isHasDialog.removeAllElements();
		ctr.d.backLis.removeAllElements();
		board = new Board(this,true, false, false,645,376,(136),(20));
		stage.clear();
		state = 0;
		board.start(ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).chapter,ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).map, ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).mapRow, ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).mapCol, ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).time, ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).numberPika, ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).stylePlay);
		Table avatar = ctr.stageHelper.createAvatar(this,stage, tweenManager, (0), (480-99), 1f);
		stage.addActor(avatar);
		super.show();
	}
	
	public void showPauseDialog(){
		ChangeListener replayLis = new ChangeListener() {						
			@Override
		public void changed(ChangeEvent arg0, Actor arg1) {
				// TODO Auto-generated method stub
					board.start(ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).chapter,ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).map, ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).mapRow, ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).mapCol, ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).time, ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).numberPika, ctr.d.maps.elementAt(Draw3Screen.INDEX_MAP).stylePlay);								
			}
		};
		ChangeListener menuLis = new ChangeListener() {						
			@Override
			public void changed(ChangeEvent arg0, Actor arg1) {
				// TODO Auto-generated method stub
				if(ctr.showMobileCore(new IMAction() {
					
					@Override
					public void action() {
						// TODO Auto-generated method stub
						postRunnable(new Runnable() {
							
							@Override
							public void run() {
								// TODO Auto-generated method stub
								ctr.a.mainSong.pause();
								ctr.a.bgSong.pause();
								ctr.a.loadedDraw();
								ctr.a.clearMusic2();
								clear();
								ctr.a.clearGame();				
								getController().setScreen(getController().getScreen("DrawScreen"));
							}
						});						
					}
				}))
				{
					return;
				}
				ctr.a.bgSong.pause();
				ctr.a.mainSong.pause();
				ctr.a.loadedDraw();
				ctr.a.clearMusic2();
				clear();
				ctr.a.clearGame();				
				getController().setScreen(getController().getScreen("DrawScreen"));
				
			}
		};
		if(ctr.a.isHasDialog() == false)
			ctr.stageHelper.createDialogPause(stage, tweenManager, menuLis, replayLis);

	}
	public void backKeyProcess(){
		if(ctr.a.isHasDialog() == true)
			return;
		//postRunnable(new Runnable() {
			
		//	@Override
		//	public void run() {
				// TODO Auto-generated method stub
				showPauseDialog();
		//	}
		//});
	}
	
	public void clear(){
		super.clear();
		if(board!=null)
		board.clear();
		board = null;
	}
}
